/**
 * https://leetcode-cn.com/problems/excel-sheet-column-title/
 * 给一个整数 columnNumber ，返回它在 Excel 表中相对应的列名称。
 * @param columnNumber 
 */
const convertToTitle = (columnNumber: number): string => {
    let str = ''
    let s = 26,
        res = 0

    const map: Record<number, string> = {
        1: 'A',
        2: 'B',
        3: 'C',
        4: 'D',
        5: 'E',
        6: 'F',
        7: 'G',
        8: 'H',
        9: 'I',
        10: 'J',
        11: 'K',
        12: 'L',
        13: 'M',
        14: 'N',
        15: 'O',
        16: 'P',
        17: 'Q',
        18: 'R',
        19: 'S',
        20: 'T',
        21: 'U',
        22: 'V',
        23: 'W',
        24: 'X',
        25: 'Y',
        26: 'Z',
    }


    // 直到小于26为止
    while ((res = columnNumber % s) <= 26) {
        // 如果为0, 那么默认就是26
        res = res === 0 ? 26 : res
        str = map[res] + str;

        // 更新columnNumber
        columnNumber = (columnNumber - res) / 26;
        if (columnNumber === 0) break;
    }

    return str;
};
// console.log(convertToTitle(28))
// console.log(convertToTitle(701))
console.log(convertToTitle(2147483647))